﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TextEditor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            System.IO.StreamReader textFile = new System.IO.StreamReader("test.txt"); // open the file for reading
            tbText.Text = textFile.ReadToEnd(); // read everything from the file, into the textbox
            textFile.Close(); // close the file (free it for other programs to access)
            textFile.Dispose(); // destroy the file handler object
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            System.IO.StreamWriter textFile = new System.IO.StreamWriter("test.txt"); // open the file for writing
            textFile.WriteLine(tbText.Text); // write the text from the textbox to the file
            MessageBox.Show("File saved successfully.");
            textFile.Close(); // close the file
            textFile.Dispose(); // destroy the file handler object
        }
    }
}
